<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>大屏</title>
    <style>
    *{margin:0;padding:0;}
    body{text-align:center;background-color:#fff;}
    </style>
</head>

<body>
    <canvas id="canvas" ></canvas>
</body>

<script src='base.js' lang="utf-8"></script>
<script src='Fullscreen.js' lang="utf-8"></script>
<script src='component.js' lang="utf-8"></script>
<script src='r/myCarrierRun.js' lang="utf-8"></script>
<script src='r/MudaoGlobal.js' lang="utf-8"></script>
<script src='r/myHTTP.js' lang="utf-8"></script>
<script src='util.js' lang="utf-8"></script>
</html>

<script>


      
      // L line add ;M move A add R 角度 S select
	function initCanvas(){
		var canvas = document.getElementById('canvas');
		canvas.tabIndex = 1000;
    var context = canvas.getContext('2d');
    canvas.height= screenHeight
    canvas.width= screenWidth
    context.clearRect(0, 0, canvas.width, canvas.height);
    context.fillStyle="#0ff";
    context.fillRect(0,0,canvas.width,canvas.height);
    context.translate(0.5,0.5);
    canvas.onkeydown =canvasKeydown;
    canvas.onkeyup =canvasKeyup;
    canvas.onmousemove =canvasMousemove
		canvas.onmouseup = canvasMouseup;
		canvas.onmousedown = canvasMousedown;
	
		return context;
	}
	
		function 	initStn(data){
		  allPath.length=0
			arrowLineList.length=0
	    addstn(context,data)
		  addrelation(context,data);
		
	}
	
	function loadsuccess(data){
	
		 context = initCanvas()
	   initStn(data)
		 globalLoadfinsh(context);
		 myReflash("sign/data",function(val){
   
      	var taskCarrier= val.data.gkCarrierStatus0.curCarrierMessage;
      	var newTaskNO="";
      	for(var path  in taskCarrier){
	      		var carrier = taskCarrier[path];
	      		var taskNo=carrier.taskNo;
	      		
	      		if(taskNo>0){
	      			if(!lastTasks[taskNo]){
			      			newTaskNO+=","+taskNo
			      			lastTasks[taskNo]=taskNo;
	      			}
	      			pathTask[carrier.id]=taskNo;
	      		}
      	}
      	if(newTaskNO){
	      		var url = "Task/carrier/"+newTaskNO.substring(1)
		      	myLoadData(url,function(val){
		  		     	var taskCarrier= val.data;
		  		     	for(var i=0;i<taskCarrier.length;i++){
		  		     			lastTasks[taskCarrier[i].taskNo]=taskCarrier[i];
		  		     	}
		      	})
      	}
      	carrierTaskRun.perClear();
      	 for(let key  in taskCarrier){
      	 	  var ss=taskCarrier[key];
        	 	if(ss.taskNo>0){
	        	 		if(!lastTasks[ss.taskNo]){
	        	 			continue;
	        	 		}
	        	 		var des = lastTasks[ss.taskNo].des;
	        	 		if(!des){
	        	 			continue;
	        	 		}
		        	 	var arr=	graph.baseDistance(ss.id,des);
		        	 	carrierTaskRun.updateTask(ss.taskNo,ss.id,arr[arr.length-2])
        	 	}
      	 	}

      	 carrierTaskRun.myClear();
      	//alert(val)
      },function(){
        	for(var i=0;i<craneList.length;i+=2){
      	       var p = Math.random();
        		      craneList[i].setGoal(p)
        		           craneList[i+1].setGoal(p)
      		}
      })
		 
		}

	
	function addstn(context,data){
				var physicalStns=	data.data.physicalStns;
				for(var i=0;i<physicalStns.length;i++){
				    var stn = 	physicalStns[i];
				    var x=stn.x||100;
				    var y=stn.y||100;
				    x=topX (x)
				    y=topY (y)
				    var l=stn.length||100
				    
				    if(stn.angle==90||stn.angle==270){
				    	    l=topX(l);
				    }else{
				    	    l=topY(l);
				    }
				
				    var color="";
				    if(stn.isKeyPoint==1){
				    	color='rgba(70,240,240,0.7)'
				    }
				  
					  allPath.push(new CarrierChain(stn.eid,context,x,y,l,stn.angle|0,0,color,stn.distance))//垂直
				}
		}
	
	
	function addrelation(context,data){
		var len = allPath.length;
		var physicalStnRelations=	data.data.physicalStnRelations;
		var errRelations = "站台异常"
		for(var i=0;i<physicalStnRelations.length;i++){
		    var rela = 	physicalStnRelations[i];
		    var begin=rela.src
		    var end=rela.next
		    	var beginCarrier={}
	   	 	  var endCarrier={}
	   	 		for(var j=0;j<len;j++){
				     	 var carrier=		allPath[j]
		     			 if(carrier.id==begin){
		     			 	  beginCarrier = carrier
		     			 }else if(carrier.id==end){
		     			 	  endCarrier = carrier
		     			 }
		     			 if(beginCarrier.id&&endCarrier.id){
		     			 		break;
		     			 }
		      }
		      
		      if(!beginCarrier.id||!endCarrier.id){
		     			 		errRelations+=rela.id+","
		     			 		continue;
		     	}
		    graph.addVector(rela.src,rela.next);
		    var cfg={context:context,x1:beginCarrier.x,y1:beginCarrier.y,x2:endCarrier.x,y2:endCarrier.y,id1:beginCarrier.id,id2:endCarrier.id};
		    
			  arrowLineList.push(new ArrowLine(cfg))//垂直
		}
	
	}
		
	window.onload = function(){
	   myLoadData("sign/stn",loadsuccess,function (data){
		 document.body.innerHTML="网络异常请刷新"
	}) 
}

    </script>
